package com.maolong.controller.system;

import com.maolong.pojo.fuction.result.Result;
import com.maolong.pojo.dto.RoleRightDTO;
import com.maolong.pojo.entity.RoleMenu;
import com.maolong.pojo.vo.MenuVo;
import com.maolong.pojo.vo.TreeRoleMenuVo;
import com.maolong.service.MenuService;
import com.maolong.service.RoleRightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("角色菜单权限管理")
@RestController
@Slf4j
@RequestMapping("/RoleRight")
public class RoleRightController {

    @Autowired
    RoleRightService roleRightService;


    @Autowired
    MenuService menuService;


    @ApiOperation("菜单权限获取")
    @GetMapping("/tree/{id}")
        public Result<TreeRoleMenuVo> getTreeData(@PathVariable Integer id) {
        log.info("获取菜单权限{}",id);
        List<MenuVo> menuVos = menuService.selectMenus();
        TreeRoleMenuVo treeRoleMenuVo = new TreeRoleMenuVo();
        treeRoleMenuVo.setData(menuVos);
        List<RoleMenu> roleMenus= roleRightService.selectRoleRight(id);
        treeRoleMenuVo.setList(roleMenus);
        return Result.success(treeRoleMenuVo);
    }

    @ApiOperation("保存菜单权限")
    @PostMapping("/save")
    public Result save(@RequestBody RoleRightDTO roleRightDTO){
        log.info("保存菜单权限{}",roleRightDTO);
        roleRightService.save(roleRightDTO);
        return Result.success();
    }
}
